package com.drguo.higouguo.service.impl;

import com.drguo.higouguo.dao.UserDao;
import com.drguo.higouguo.entity.User;
import com.drguo.higouguo.service.UserService;
import com.drguo.higouguo.utils.GuoUtil;

public class UserServiceImpl implements UserService {
	private UserDao userDao;

	@Override
	public void register(User user) {
		user.setId(GuoUtil.getId());
		user.setRegTime(GuoUtil.getNowTime());
		user.setRole("u");
		userDao.addUser(user);
		
	}
	
	@Override
	public User login(String name, String password) {
		
		return userDao.getUserByNameAndPwd(name, password);
	}
	
	//唯一性验证
	@Override
	public boolean isExist(String name) {
		int num = userDao.getNumByName(name);
		return num!=0;
	}
	//更新头像
	@Override
	public void updateAvatar(String id, String avatar) {
		userDao.updateAvatar(id, avatar);
	}

	public UserDao getUserDao() {
		return userDao;
	}
	
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

}
